package com.example.listener;

import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 *@Description 任务委派
 *@Author 庞留杰
 *@Date2022/2/25 17:33
 *@Version V1.0
 **/
@Slf4j
@Component
public class LoanDelegate implements JavaDelegate {

    @Override
    public void execute(DelegateExecution delegateExecution) {
        System.out.println(">>>>>>>>> 任务委派 >>>>>>>>>>");
        Map<String, Object> variables1 = delegateExecution.getVariables();
        System.out.println("variables1------------"+variables1);
        Map<String, Object> variables2 = delegateExecution.getParent().getVariables();
        System.out.println("variables2------------"+variables2);

//        Double yearWages = (Double) delegateExecution.getVariable("yearWages");
//        Double houseAssets = (Double) delegateExecution.getVariable("houseAssets");
//        double sum = yearWages + houseAssets;
//        if (sum <= 0) {
//            delegateExecution.setVariable("creditRating", "C");
//            delegateExecution.setVariable("loanLimit", 0);
//        } else if (sum > 0 && sum <= 100) {
//            delegateExecution.setVariable("creditRating", "B");
//            delegateExecution.setVariable("loanLimit", sum * 0.8);
//        } else if (sum > 100) {
//            delegateExecution.setVariable("creditRating", "A");
//            delegateExecution.setVariable("loanLimit", sum * 1.2);
//        }
        System.out.println("delegateExecution...."+delegateExecution);
    }
}